<template>
	<view>
		<zmm-watermark :watermark="userStore.watermark" v-if="userStore && userStore.watermark"></zmm-watermark>
		<view class="content detail">
			<!--商品信息-->
			<view class="detail-item">
				<uni-section title="商品信息" type="line"></uni-section>
				<view class="detail-content">
					<view class="detail-text">
						区域：
						<uni-tag size="small" :text="arrText(setStore.allProvinceList, info.regionCode)" />
					</view>
					<view class="detail-text">
						产品名称：
						<text>{{info.productName}}</text>
					</view>
					<view class="main-flex detail-text detail-flex-start">
						商品简图：
						<view class="detail-text_r">
							<up-image width="120rpx" height="120rpx" @click.stop="previewImg(info.sellImage)" :src="info.sellImage" :lazy-load="true"></up-image>
						</view>
					</view>
					<view class="detail-text">
						销售渠道：
						<uni-tag :class="`sellChannel${info.sellChannel}`" size="small" :text="arrText(sellChannelList, info.sellChannel)" />
					</view>
				</view>
			</view>
			<!--活动信息-->
			<view class="detail-item">
				<uni-section title="活动信息" type="line"></uni-section>
				<view class="detail-content">
					<view class="detail-text">活动名称：<text>{{info.seckillName}}</text></view>
					<view class="detail-text">活动类别：<uni-tag size="small" :text="arrText(productTypeList, info.seckillType)" /></view>
					<view class="main-flex detail-text detail-flex-start">
						秒杀简图：
						<view class="detail-text_r">
							<up-image width="120rpx" height="120rpx" @click.stop="previewImg(info.seckillImage)" :src="info.seckillImage" :lazy-load="true"></up-image>
						</view>
					</view>
					<view class="detail-text">秒杀预告：<text>{{info.seckillNotice}}</text></view>
					<view class="detail-text">仅活动区：<uni-tag size="small" :type="info.onlyDisplaySeckill === 1 ? 'success' : ''" :text="info.onlyDisplaySeckill === 1 ? '是' : '否'" /></view>
					<view class="detail-text">销售价：<text>{{info.sellPrice}}</text></view>
					<view class="detail-text">秒杀价：<text>{{info.seckillPrice}}</text></view>
					<view class="detail-text">开始时间：<text>{{info.startTime}}</text></view>
					<view class="detail-text">结束时间：<text>{{info.endTime}}</text></view>
					<view class="detail-text">状态：<uni-tag size="small" :text="arrText(seckillStatusList, info.status)" /></view>
					<view class="detail-text">备注：<text>{{info.remark}}</text></view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { computed, onMounted, ref } from 'vue';
import { tab, auth, modal } from "@/plugins"
import { getTitle } from "@/utils/getter"
import { checkPermi, checkRole, checkOnlyPermi, checkOnlyRole } from "@/utils/permission"
import { seckillDetail, productType } from "@/api/erp_api/product"
import { allProvince } from "@/api/erp_api/region"
import { copyText, arrText, previewImg } from '@/utils/ty.js';
import { sellChannelList, seckillStatusList } from '@/utils/config.js'
import useUserStore from '@/store/modules/user'
import useSetStore from '@/store/modules/set'

	const userStore = useUserStore()
	const setStore = useSetStore()
	onLoad(async (option) => {
		if (option.id) {
			id.value = option.id
			await getProductType()
			getDetail()
		}
	})
	
	// 获取商品类别
	const productTypeList = ref([])
	const getProductType = () => {
		return productType().then(res => {
			productTypeList.value = res.rows.map(item => {
				return {
					...item,
					value: item.id,
					text: `${item.parentName}->${item.name}`
				}
			}).filter(item => item.parentId) || []
		})
	}
	
	// 数据查询
	const id = ref('')
	const info = ref({})
	const isLoading = ref(false)
	
	const getDetail = () => {
		const params = {
			id: id.value
		}
		isLoading.value = true
		uni.showLoading({
			title: '数据加载中...'
		})
		seckillDetail(params).then(res => {
			info.value = res.data || {}
			isLoading.value = false
			uni.hideLoading()
    }).catch(() => {
			isLoading.value = false
			uni.hideLoading()
		})
	}
	
</script>

<style scoped lang="scss">
.detail-text-integral {
	margin-left: 20rpx;
}
.detail-text-banners {
	margin-left: -10rpx;
}
.detail-text-banner {
	margin: 0 10rpx 10rpx;
}
.detail-text-video {
	width: 100%;
	height: 250rpx;
}
</style>
